package com.kkb.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kkb.mapper.HosSettleMapper;
import com.kkb.pojo.Hospitalization;
import com.kkb.vo.SettleQueryVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class HosSettleService {

    @Resource
    private HosSettleMapper hosSettleMapper;

    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
    public PageInfo<Hospitalization> selectInPage(Integer index, Integer size, SettleQueryVO vo){
        if (vo.getHosName()!=null&&vo.getHosName().trim().isEmpty()){
            vo.setHosName(null);
        }else {
            vo.setHosName("%"+vo.getHosName().trim()+"%");
        }
        PageHelper.startPage(index,size);
        List<Hospitalization> hospitalizationList = hosSettleMapper.selectWithRegister(vo);
        return new PageInfo<>(hospitalizationList);
    }

}
